package ejb.facades.extra;

import ejb.facades.AbstractFacade;
import entities.User;
import entities.extra.UserTripParticipation;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Trabalho PD - 2014/2015
 * @author a21210380 a21210392
 */
@Stateless
public class UserTripParticipationFacade extends AbstractFacade<UserTripParticipation> implements UserTripParticipationFacadeLocal {
    @PersistenceContext(unitName = "Trabalho_PDPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UserTripParticipationFacade() {
        super(UserTripParticipation.class);
    }
    
    @Override
    public List<UserTripParticipation> findAppointedTripFor(User user) {
        return em.createNamedQuery("UserTripParticipation.findAppointedTripFor", UserTripParticipation.class)
                .setParameter(1, user.getId())
                .getResultList();
    }
    
    @Override
    public List<UserTripParticipation> findTripHistoricFor(User user) {
        return em.createNamedQuery("UserTripParticipation.findTripHistoricFor", UserTripParticipation.class)
                .setParameter(1, user.getId())
                .getResultList();
    }
}
